package com.java110.mall.shop.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.core.context.Environment;
import com.java110.po.shop.ShopHousePo;
import com.java110.mall.shop.bmo.shopHouse.IDeleteShopHouseBMO;
import com.java110.mall.shop.bmo.shopHouse.IGetShopHouseBMO;
import com.java110.mall.shop.bmo.shopHouse.ISaveShopHouseBMO;
import com.java110.mall.shop.bmo.shopHouse.IUpdateShopHouseBMO;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/shopHouse")
public class ShopHouseApi {

    @Autowired
    private ISaveShopHouseBMO saveShopHouseBMOImpl;
    @Autowired
    private IUpdateShopHouseBMO updateShopHouseBMOImpl;
    @Autowired
    private IDeleteShopHouseBMO deleteShopHouseBMOImpl;

    @Autowired
    private IGetShopHouseBMO getShopHouseBMOImpl;

    /**
     * 微信保存消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /shopHouse/saveShopHouse
     * @path /app/shopHouse/saveShopHouse
     */
    @RequestMapping(value = "/saveShopHouse", method = RequestMethod.POST)
    public ResponseEntity<String> saveShopHouse(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "shName", "请求报文中未包含shName");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");


        ShopHousePo shopHousePo = BeanConvertUtil.covertBean(reqJson, ShopHousePo.class);
        return saveShopHouseBMOImpl.save(shopHousePo);
    }

    /**
     * 微信修改消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /shopHouse/updateShopHouse
     * @path /app/shopHouse/updateShopHouse
     */
    @RequestMapping(value = "/updateShopHouse", method = RequestMethod.POST)
    public ResponseEntity<String> updateShopHouse(@RequestBody JSONObject reqJson) {
        Environment.isDevEnv();
        Assert.hasKeyAndValue(reqJson, "shName", "请求报文中未包含shName");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");
        Assert.hasKeyAndValue(reqJson, "shId", "shId不能为空");


        ShopHousePo shopHousePo = BeanConvertUtil.covertBean(reqJson, ShopHousePo.class);
        return updateShopHouseBMOImpl.update(shopHousePo);
    }

    /**
     * 微信删除消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /shopHouse/deleteShopHouse
     * @path /app/shopHouse/deleteShopHouse
     */
    @RequestMapping(value = "/deleteShopHouse", method = RequestMethod.POST)
    public ResponseEntity<String> deleteShopHouse(@RequestBody JSONObject reqJson) {
        Environment.isDevEnv();
        Assert.hasKeyAndValue(reqJson, "shId", "shId不能为空");


        ShopHousePo shopHousePo = BeanConvertUtil.covertBean(reqJson, ShopHousePo.class);
        return deleteShopHouseBMOImpl.delete(shopHousePo);
    }


}
